﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UDDL.Model;
using System.IO;

namespace UDDL.CodeGeneration.CPP
{
	class CppDataDescription
	{
		internal CppDataDescription(DataDescription dataDescription)
		{
			Root = new CppNamespace(null, dataDescription.Root);
		}

		public void GenerateCode(DirectoryInfo directory)
		{
			List<CppEntity> entities = GetEntities();
			foreach (CppEntity entity in entities)
			{
				using (CppFile file = new CppFile(Path.Combine(directory.FullName,Path.ChangeExtension(entity.Filename,".h"))))
				{
					entity.GenerateCode(file);
				}
			}

		}

		public List<CppEntity> GetEntities()
		{
			List<CppEntity> entities = new List<CppEntity>();
			Root.CollectEntities(entities);
			return entities;
		}

		public CppNamespace Root { get; private set; }
	}
}
